<template>
    <div>
        <el-row>
            <el-input class="selectinput" placeholder="请输入内容">
                <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
        </el-row>
        <el-row>
            <el-tabs @tab-click='tabClick'>
                <el-tab-pane>
                    <span slot="label"><i class="icon-snippetsbox-codesquareo"></i></span>
                    <el-card class="box-card">
                      <div slot="header" class="clearfix">
                        <span>CODE</span>
                      </div>
                      <div class="text item">
                        <el-tree :data="codelist" :props="codeProps" @node-click="codeNodeClick"></el-tree>
                      </div>
                    </el-card>
                </el-tab-pane>
                <el-tab-pane>
                    <span slot="label"><i class="icon-snippetsbox-tag-o"></i></span>
                    <el-card class="box-card">
                      <div slot="header" class="clearfix">
                        <span>TAGS</span>
                      </div>
                      <div class="text item">
                        <el-tree :data="taglist" :props="defaultProps" @node-click="tagNodeClick"></el-tree>
                      </div>
                    </el-card>
                </el-tab-pane>
            </el-tabs>
        </el-row>
    </div>
</template>
<script>
import eventVue from '../../assets/eventVue'
export default {
  data () {
    return {
      taglist: null,
      codelist: null,
      defaultProps: {
        label: 'tname'
      },
      codeProps: {
        label: 'cname'
      }
    }
  },
  mounted () {
    this.$http.get(this.GLOBAL.serverSrc + this.GLOBAL.codeall).then(
      response => {
        console.log(response.data)
        this.codelist = response.data
      })
  },
  methods: {
    tabClick (data) {
      if (data.index === '1') {
        this.$http.get(this.GLOBAL.serverSrc + this.GLOBAL.tags).then(
          response => {
            this.taglist = response.data
          })
      } else {
        this.$http.get(this.GLOBAL.serverSrc + this.GLOBAL.codeall).then(
          response => {
            this.codelist = response.data
          })
        this.$emit('listenToListMenuShow', { value: false })
      }
    },
    tagNodeClick (data) {
      eventVue.$emit('listenToFillList', { key: data.tid, value: data.tname })
      this.$emit('listenToListMenuShow', { value: true })
    },
    codeNodeClick (data) {
      console.log(data)
      eventVue.$emit('listenToCodeId', { key: data.cid, value: data.cname })
    }
  }
}
</script>
<style>
  .text {
    font-size: 12px;
  }
  
  .clearfix > span{
    font-size: 12px;
    color: #C2C3C9;
  }
  .el-card__header{
    padding: 6px 20px;
  }
  .el-card__body{
    padding-top: 10px;
    padding-left: 0px;
    padding-right: 0px;
    width: 100%;
  }
</style>

